<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\shusy_sweepstake\Entity\ShusySweepstakeItem;

/**
 * @OA\Schema(
 *   schema="SweepstakeItem",
 *   type="object",
 *   description="SweepstakeItem"
 * )
 */
class SweepstakeItem extends AbstractBaseModel {

  protected function getEntityType() {
    return 'shusy_sweepstake_item';
  }

  protected function setValue() {
    if ($this->entity instanceof ShusySweepstakeItem) {
      $icon = (string) $this->imageStyleUrl('SweepstakeItemIcon', file_load($this->entity->image));
      //      $str = file_get_contents($icon);
      //      $base64 = drupal_base64_encode($str);
      $value = [
        /**
         * @OA\Property(
         *   property="name",
         *   type="string",
         *   description="奖项名",
         * ),
         */
        'name' => (string) $this->entity->name,
        /**
         * @OA\Property(
         *   property="icon",
         *   type="string",
         *   description="奖项图标",
         * ),
         */
        'icon' => $icon,
        'base64' => "",
        /**
         * @OA\Property(
         *   property="type",
         *   type="integer",
         *   description="奖品类型 0 谢谢惠顾 1 积分 2 实物",
         * ),
         */
        'type' => (int) $this->entity->type,
      ];
      $this->merge($value);
    }
  }
}
